import uvicorn
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from starlette.exceptions import HTTPException as StartletteHTTPException
from fastapi.exceptions import RequestValidationError
from fastapi.responses import PlainTextResponse
from st.tutorial import c01, c02, c03, c04, c05
from st.coronavirus import application

app = FastAPI()

app.mount(path='/static', app=StaticFiles(directory='../st/coronavirus/static'), name='static')

# @app.exception_handler(StartletteHTTPException)  # 重写错误异常处理提示
# async def http_exception_handler(request, exc):
#     """
#
#     :param request: 必填参数
#     :param exc:
#     :return:
#     """
#     return PlainTextResponse(str(exc.detail), status_code=exc.status_code)
#
#
# @app.exception_handler(RequestValidationError)  # 重写请求验证异常处理器
# async def validation_exception_handler(request, exc):
#     """
#     :param request: 必填参数
#     :param exc:
#     :return:
#     """
#     return PlainTextResponse(str(exc.detail), status_code=exc.status_code)


app.include_router(c01, prefix='/c01', tags=['c01'])
app.include_router(c02, prefix='/c02', tags=['c02'])
app.include_router(c03, prefix='/c03', tags=['c03'])
app.include_router(c04, prefix='/c04', tags=['c04'])
app.include_router(c05, prefix='/c05', tags=['c05'])
app.include_router(application, prefix='/application', tags=['application'])

if __name__ == '__main__':
    uvicorn.run("main:app", host='0.0.0.0', port=5555, reload=True, debug=True)
